package edu.byui.chat;

import java.util.ArrayList;
import java.util.HashMap;

public class AppController {
	private static HashMap <String, String> commandMap;
	static {
		commandMap = new HashMap<String, String>();
		commandMap.put("login", "edu.byui.chat.LoginCommand");
		commandMap.put("get", "edu.byui.chat.GetCommand");
		commandMap.put("send", "edu.byui.chat.SendCommand");
		commandMap.put("logout", "edu.byui.chat.LogoutCommand");
		commandMap.put("read", "edu.byui.chat.ReadCommand");
	}

	
	@SuppressWarnings("unchecked")
	public static void handleRequest(ArrayList parameters) {
		String call = (String) ((Command) parameters.get(0)).getHeader();		
		try {
			Class aClass = Class.forName((String)commandMap.get(call));
			Sub aSub = (Sub)aClass.newInstance();
			aSub.runSub(parameters);
		}
		catch (InstantiationException e) {
			e.printStackTrace();
		}
		catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}
}
